﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LineWatch_WinForm
{
    public partial class SeBeiGuZhangView : Form
    {
        public SeBeiGuZhangView()
        {
            InitializeComponent();

            this.InitFont();

            this.lblActualCompletedLine1.Text = ConfigInfo.ActualCompleted;
            this.lblStopTimeLine1.Text = ConfigInfo.StopTime;
        }

        private void btnRetrn_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void timerProductInfo_Tick(object sender, EventArgs e)
        {
            this.lblActualCompletedLine1.Text = ConfigInfo.ActualCompleted;
            this.lblStopTimeLine1.Text = ConfigInfo.StopTime;
        }


        /// <summary>
        /// Init Font
        /// </summary>
        private void InitFont()
        {
            foreach (Control control in this.Controls)
            {
                if (control.GetType() == typeof(Label))
                {
                    Label lbl = (Label)control;
                    if (lbl.Tag != null)
                    {
                        this.UpdateFont(lbl);
                    }
                }

                InitFont(control);
            }
        }

        /// <summary>
        /// Init Font
        /// </summary>
        /// <param name="controlParent"></param>
        private void InitFont(Control controlParent)
        {
            foreach (Control control in controlParent.Controls)
            {
                if (control.GetType() == typeof(Label))
                {
                    Label lbl = (Label)control;
                    if (lbl.Tag != null)
                    {
                        this.UpdateFont(lbl);
                    }
                }

                InitFont(control);
            }
        }

        /// <summary>
        /// Update Font
        /// </summary>
        /// <param name="control"></param>
        private void UpdateFont(Control control)
        {
            if (control.Tag.ToString().StartsWith("CommentFontSizeTitle"))
            {
                this.SetFont(control, "Microsoft YaHei", ConfigInfo.CommentFontSizeTitle, FontStyle.Bold);
            }
            else if (control.Tag.ToString().StartsWith("CommentFontSizeCaption"))
            {
                this.SetFont(control, "Microsoft YaHei", ConfigInfo.CommentFontSizeCaption, FontStyle.Bold);
            }
            else if (control.Tag.ToString().StartsWith("CommentFontSizeValue"))
            {
                this.SetFont(control, "Microsoft YaHei", ConfigInfo.CommentFontSizeValue, FontStyle.Bold);
            }
        }

        /// <summary>
        /// Set Font
        /// </summary>
        /// <param name="control"></param>
        /// <param name="familyName"></param>
        /// <param name="emSize"></param>
        /// <param name="style"></param>
        private void SetFont(Control control, string familyName, float emSize, FontStyle style)
        {
            control.Font = new System.Drawing.Font(familyName,
                                                   emSize,
                                                   style,
                                                   System.Drawing.GraphicsUnit.Point,
                                                   ((byte)(0))
                                                   );
        }

        private void btnSetting_Click(object sender, EventArgs e)
        {
            Setup form = new Setup();
            form.ShowDialog();
        }
    }
}
